var __UIGarage_instance = null;
function getUIGarage() { return __UIGarage_instance; }

var UIGarage = function(){};

UIGarage.prototype.onDidLoadFromCCB = function()
{
    cc.log("UIGarage.onDidLoadFromCCB");
    __UIGarage_instance = this;

    // 车库类
    this._garage = new Garage();
    this.uiGarageRoot.addChild(this._garage);

    // 车库按钮
    //this._setSelectedBtn(this.uiBtnGarage);

    // 背包类
    this._bag = new UIBag(this.uiBagRoot.getPosition());
    this.uiBagRoot.addChild(this._bag);

};

UIGarage.prototype.getGarage = function()
{
    return this._garage;
}

UIGarage.prototype.getBag = function()
{
    return this._bag;
}

// 发送设置主界面数据
UIGarage.prototype.updateData = function()
{
    cc.log('UIGarage.updateData');

    this.updateHead();
    this.updateGarage();
    this.updateItems();
}


// 头像 --------------------------------------
UIGarage.prototype.updateHead = function()
{
    cc.log('UIGarage.updateHead');
    var d = DataManager.player;
    this.uiName.setString(d.name);
    this.uiLevel.setString('Lv'+d.lv + ' 头衔');

    this.uiResource.setString(''+d.money);
    this.uiGold.setString(''+d.gold);
    this.uiEnergy.setString(''+d.energy);
}

// 车库 --------------------------------------
UIGarage.prototype.updateGarage = function()
{
    cc.log('UIGarage.updateGarage');
    var d = DataManager.playerTanks;
    if (d) this._garage.setTanksData(d, helper.SIDE_DOWN);
}



// 道具 --------------------------------------
UIGarage.prototype.updateItems = function()
{
    cc.log('UIGarage.updateItems');
    var d = DataManager.playerItems;
    this._bag.setData(d)
    //if (d) this._garage.setTanksData(d, helper.SIDE_DOWN);
}

// MainTab ------------------------------------


// 车库 
UIGarage.prototype.onGarage = function()
{
    getUIMain().hideAll();
    this._setSelectedBtn(this.uiBtnGarage);
};

// 整备
UIGarage.prototype.onEquip = function()
{

    this._setSelectedBtn(this.uiBtnEquip);
};

// 强化
UIGarage.prototype.onStrongthen = function()
{

    this._setSelectedBtn(this.uiBtnStrongthen);
};

// 商店
UIGarage.prototype.onShop = function()
{
    this._setSelectedBtn(this.uiBtnShop);
};

// 知识
UIGarage.prototype.onKnowledge = function()
{
    this._setSelectedBtn(this.uiBtnKnowledge);

    var timestamp = new Date().getTime();
    cc.log(timestamp)

};

// 战役
UIGarage.prototype.onBattle = function()
{
    getUIMain().openUIStory(true);
    this._setSelectedBtn(this.uiBtnBattle);
};

UIGarage.prototype._setSelectedBtn = function (btn) 
{
    if(this._selectedBtn) {
        this._selectedBtn.unselected();
    }
    btn.selected();
    this._selectedBtn = btn;
};

UIGarage.prototype.clearSelectedBtn = function (btn) 
{
    if(this._selectedBtn) {
        this._selectedBtn.unselected();
    }
    this._selectedBtn = null;
}
